package jwebtester.security.auth;

import infrastructure.Scopes;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.stereotype.Service;

/**
 * Represents custom provider to wrap Hibernate based
 * {@link UserDetailsService} and custom {@link Sha512PasswordEncoder}
 * 
 * @author iternovy
 * 
 */
@Service
@Scope(Scopes.Singleton)
public class HibernateAuthenticationProvider extends DaoAuthenticationProvider {

	private static final Logger LOG = LoggerFactory
			.getLogger(HibernateAuthenticationProvider.class);

	@Autowired
	public HibernateAuthenticationProvider(final UserDetailsService usersService) {
		super();

		LOG.info(String.format("Created %s. UserDetailsService=%s", this.getClass(),
				usersService.getClass()));

		setUserDetailsService(usersService);
		setPasswordEncoder(new Sha512PasswordEncoder());
	}
}
